<?php

namespace app\common\model;

use think\Model;

/**
 * 会员配置
 */
class LevelConfig extends Model
{

    // 追加属性
    protected $append = [
        'json_array'
    ];
    public function getJsonArrayAttr($value, $data)
    {
        if ($data['json']) {
            return json_decode($data['json']);
        }
        return '';
    }

    static function getVipFee($money, $level_id)
    {
        $vip = self::get(1);
        $discount = bcdiv($vip->discount, 100, 2);
        if ($discount > 0 && $level_id > 0) {
            $vip_money = bcmul($money, $discount, 2);
            return $vip_money > 0 ? $vip_money : 0;
        }
        return $money;
    }
}
